<%@ page contentType="application/json; charset=UTF-8" pageEncoding="UTF-8" errorPage="/error.jsp"%>
<%@page import="dbexp.model.Column"%>
<%@page import="dbexp.model.Index"%>
<%@page import="dbexp.model.db.DbUser"%>
<%@page import="dbexp.connection.DbMetaData"%>
<%@page import="dbexp.connection.DbConnection"%>
<%@page import="org.json.JSONObject"%>
<%
DbUser u = (DbUser)session.getAttribute("USER");
String name = request.getParameter("name");
String schema = request.getParameter("schema");
String action = request.getParameter("action");
String onSchema = request.getParameter("onSchema");
String onTable = request.getParameter("onTable");
String unique = request.getParameter("unique");
String bitmap = request.getParameter("bitmap");
String reverse = request.getParameter("reverse");
String columns = request.getParameter("columns");

boolean brak = (name==null || name.trim().equals("null")) && (schema==null || schema.trim().equals("null"));
Index ob =  new Index(name,schema);
if(onSchema!=null){
	ob.setOnSchema(onSchema);
}
if(onTable!=null){
	ob.setOnTable(onTable);
}
ob.setUnique(unique!=null);
ob.setBitmap(bitmap!=null);
ob.setReverse(reverse!=null);
if(columns!=null){
	String[] _columns=columns.split(",");
	for(int i=0;i<_columns.length;i++){
		if(_columns[i].trim().length()>0){
			ob.addColumn(new Column(_columns[i], onSchema, onTable));
		}
	}
}
if(!brak && action.equals("create")){
	int status = DbMetaData.operateObject(u,ob,DbConnection.CREATE);
}
	ob = DbMetaData.getIndex(u, name, schema);
out.clearBuffer();%><%=new JSONObject().
													put("success", true).
													put("data",new JSONObject().
															put("name", ob.getName()).
															put("schema",ob.getSchema()).
															put("onSchema",ob.onSchema()).
															put("onTable",ob.onTable()).
															put("unique",ob.isUnique()).
															put("reverse",ob.isReverse()).
															put("bitmap",ob.isBitmap()))%>